package util

import (
	"fmt"
	"strconv"
	"strings"
)

//波动率
func Volatility(priceA float64,priceB float64) float64 {
	wave := (priceA - priceB) / priceA
	return wave
}

func  AdaptOType(side string, positionSide string) int {
	if positionSide == "BOTH" && side == "SELL" {
		return OPEN_SELL
	}

	if positionSide == "BOTH" && side == "BUY" {
		return OPEN_BUY
	}

	if positionSide == "LONG" {
		switch side {
		case "BUY":
			return OPEN_BUY
		default:
			return CLOSE_BUY
		}
	}

	if positionSide == "SHORT" {
		switch side {
		case "SELL":
			return OPEN_SELL
		default:
			return CLOSE_SELL
		}
	}

	return 0
}

func PairChangeCurrency(currencyPair string)(string,string){
	UpCurrencyPair := strings.ToUpper(currencyPair)
	if strings.Contains(currencyPair,"_"){
		currencys := strings.Split(UpCurrencyPair,"_")
		currencyA :=currencys[0]
		currencyB :=currencys[1]
		return currencyA,currencyB
	}else if strings.Contains(UpCurrencyPair,"USDT"){
		currencyA := strings.ReplaceAll(currencyPair,"USDT","")
		currencyB :="USDT"
		return currencyA,currencyB
	}else if strings.Contains(UpCurrencyPair,"USD"){
		currencyA := strings.ReplaceAll(currencyPair,"USD","")
		currencyB :="USD"
		return currencyA,currencyB
	}else {
		return "",""
	}
}

//判断两个结构体是否相同
func CompareTwoMapInterface(nOrderMap,oOrderMap map[string]interface{}) bool {
	for k, v := range nOrderMap {
		if oOrderMap[k] != v {
			return false
		}
	}
	return true
}

func Decimal(value float64) float64 {
	value, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", value), 64)
	return value
}
